package com.cjh.admin.controller;

import com.alibaba.fastjson.JSON;
import com.cjh.admin.config.TokenThreadLocal;
import com.cjh.common.dto.ClerkPagingDTO;
import com.cjh.common.entity.Clerk;
import com.cjh.common.response.Result;
import com.cjh.common.service.ClerkService;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/clerk")
public class ClerkController {

    @Autowired
    ClerkService clerkService;

    @ApiOperation("获取所有员工")
    @GetMapping("/getAllClerk")
    public Result getAllClerk(@RequestParam String clerkPagingDTO){
        ClerkPagingDTO clerkPagingDTO1 = JSON.parseObject(clerkPagingDTO, ClerkPagingDTO.class);
        clerkPagingDTO1.setDbUserName(TokenThreadLocal.get());
        return clerkService.getAllClerk(clerkPagingDTO1);
    }

    @RequiresPermissions(value = {"addClerk"})
    @ApiOperation("增加员工")
    @PostMapping("/addClerk")
    public Result addClerk(@RequestBody Clerk clerk){
        return clerkService.addClerk(clerk);
    }

    @RequiresPermissions(value = {"deleteClerk"})
    @ApiOperation("删除员工")
    @PostMapping("/deleteClerk")
    public Result deleteClerk(@RequestBody Clerk clerk){
        return clerkService.deleteClerk(clerk);
    }

    @RequiresPermissions(value = {"deleteClerk"})
    @ApiOperation("删除多个员工")
    @PostMapping("/deleteManyClerk")
    public Result deleteManyClerk(@RequestBody List<Clerk> clerk){
        return clerkService.deleteManyClerk(clerk);
    }
}
